﻿// Copyright 2010 Maxime Serrano <lastchronicler@gmail.com>
using System;
using System.Net;

namespace MCSharp {
    static class DebugCommands {
        internal static void Init() {
            CommandList.RegisterCommand(cdDebug);
        }

        static CommandDescriptor cdDebug = new CommandDescriptor {
            name = "debug",
            consoleSafe = false,
            permissions = new Permission[] { Permission.Debug },
            usage = "/debug <command> <params>",
            help = "Easy debugging commands.",
            handler = cmdDebug
        };

        internal static void cmdDebug(Player player, Command cmd) {
            string command = cmd.Next();
            if (command == null) {
                player.Message(Color.Announcement + "You must enter a debug command");
                return;
            }
            switch (command) {
                case "oddblocks":
                    for (int x = -16; x < 16; x++) {
                        for (int y = 0; y < 128; y++) {
                            for (int z = -16; z < 16; z++) {
                                ChunkBlock block = Server.world.GetBlock(x, (byte)y, z);
                                Server.world.SetBlock(block, x, (byte)y, z);
                                Server.SendToAll(PacketWriter.MakeBlockChange(block, x, (byte)y, z));
                            }
                        }
                    }
                    break;
                default:
                    player.Message(Color.Announcement + "Unknown debug command: " + command);
                    break;
            }
        }
    }
}